function[r,Ch_fft]=corre_mimochannel(v,fc,samplingrate,num_perframe,delay,power,data,Tr,Rr,block,leng,ifft_length,Gp_length,Gp_length_long,K,cor,gauss_seed,chan_gen,jump_flag,user_index)
% r: h*x
% Ch_fft: ideal channeldata
% Gauss seed is a value
%Channel=zeros(Tr*Rr,num_perframe);
[R_tr,R_re,R]=corre_matrix(Tr,Rr,cor);
tap_fft=zeros(ifft_length,block,Tr*Rr);
r=zeros(Rr,num_perframe);
path_num=length(delay);
Channel = zeros(Tr*Rr, num_perframe);
Ch_fft = zeros(Tr*Rr, ifft_length*block); % ideal channeldata

if chan_gen ~= 0 && jump_flag ==1;
    r = [];
    Ch_fft = [];
    return;
end;
switch user_index
    case 1,
        seed_1 = 1234;
        seed_2 = 256253; 
    case 2,
        seed_1 = 3456;
        seed_2 = 256777;
    case 3,
        seed_1 = 5678;
        seed_2 = 256663;
    case 4,
        seed_1 = 6789;
        seed_2 = 666253;
    otherwise,
        seed_1 = 7890;
        seed_2 = 743243;
end;

for k=1:length(delay)
  
    for tx=1:Tr
        for rx=1:Rr
            % gauss_seed=tx*856+rx*256;
%           temp_gauss_seed=tx*1234+rx*256253;
            temp_gauss_seed=tx*seed_1+rx*seed_2;
%           temp_gauss_seed=tx*gauss_seed+rx*(gauss_seed+256253);
            channel1T1R=fading_corchannel(v,fc,samplingrate,num_perframe,power,temp_gauss_seed,Tr,Rr,tx,rx,path_num,k,K,chan_gen,user_index);
            Channel(rx+(tx-1)*Rr,:)=channel1T1R;%һ��һ�գ�����һ�գ�һ�����գ���������
        end
    end
    
    if chan_gen == 0 && jump_flag == 1
        r = [];
        Ch_fft = [];
        continue;
    end;
    
    clear channel1T1R;
    Ch=R*Channel;
    clear Channel;

    Ch_temp=Ch;
    Ch_temp(:,[[1:Gp_length_long-Gp_length] num_perframe/2+[1:Gp_length_long-Gp_length]])=[];
    for L=1:Tr*Rr
        a=reshape(Ch_temp(L,:),(ifft_length+Gp_length),block);
        a(1:Gp_length,:)=[];
        tap=sum(a)/ifft_length;
        tap_fft(delay(k)+1,:,L)=tap;
    end
    clear Ch_temp;

    if k==1
        data_temp=data;
    else
        data_temp=[zeros(size(data,1),delay(k)),data(:,1:length(data)-delay(k))];
    end
 
    for tt=1:Tr
        for ttt=1:Rr
            temp=data_temp(tt,:).*Ch(ttt+(tt-1)*Rr,:);
            r(ttt,:)=r(ttt,:)+temp;
        end
    end

    clear temp
    clear data_temp;
    clear Ch;
end
tap_fft=fft(tap_fft);
ss=reshape(tap_fft,1,ifft_length*block,Tr*Rr);
for m=1:Tr*Rr
    Ch_fft(m,:)=ss(:,:,m);
end
clear path_num
clear ss;
clear R_tr R_re R
clear tap_fft


